package com.example.qingyiapp.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.example.qingyiapp.R;
import com.example.qingyiapp.service.entify.Databean;
import com.example.qingyiapp.service.entify.FindFriend;
import com.example.qingyiapp.service.entify.FindTJBean;
import com.example.qingyiapp.service.entify.FriendSquareBean;
import com.example.qingyiapp.service.entify.FriendXxBean;
import com.example.qingyiapp.service.entify.IntrodutioBean;
import com.example.qingyiapp.service.presenter.PersenterMannaer;
import com.example.qingyiapp.service.view.IChildView;
import com.example.qingyiapp.ui.activity.fragment.fragment_AddressUI.address_bean.JavaBean_lv;
import com.example.qingyiapp.ui.activity.fragment.fragment_AddressUI.address_bean.JavaBean_lv2;
import com.example.qingyiapp.ui.activity.fragment.fragment_AddressUI.address_bean.JavaBean_lv3;
import com.example.qingyiapp.ui.activity.fragment.fragment_AddressUI.address_bean.JavaBean_msg;
import com.example.qingyiapp.ui.activity.fragment.fragment_FindUI.utils.MyListView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class Friend_xr_item_activity extends AppCompatActivity {

    @BindView(R.id.back)
    ImageView back;
    @BindView(R.id.share)
    ImageView share;
    @BindView(R.id.xr_item_head_image_sdf)
    ImageView xrItemHeadImageSdf;
    @BindView(R.id.xr_item_title_sdf)
    TextView xrItemTitleSdf;
    @BindView(R.id.topre)
    RelativeLayout topre;
    @BindView(R.id.leftimage1)
    ImageView leftimage1;
    @BindView(R.id.centerimage1)
    ImageView centerimage1;
    @BindView(R.id.leftimage2)
    ImageView leftimage2;
    @BindView(R.id.one)
    RelativeLayout one;
    @BindView(R.id.leftimage)
    ImageView leftimage;
    @BindView(R.id.centerimage)
    ImageView centerimage;
    @BindView(R.id.rightimage)
    ImageView rightimage;
    @BindView(R.id.three)
    RelativeLayout three;
    @BindView(R.id.time)
    TextView time;
    @BindView(R.id.address)
    TextView address;
    @BindView(R.id.laddress)
    TextView laddress;
    @BindView(R.id.laddressimage)
    ImageView laddressimage;
    @BindView(R.id.laddressimage2)
    ImageView laddressimage2;
    @BindView(R.id.numpeople)
    TextView numpeople;
    @BindView(R.id.tel)
    TextView tel;
    @BindView(R.id.xx)
    TextView xx;
    @BindView(R.id.sxlz)
    Button sxlz;
    @BindView(R.id.xxly)
    Button xxly;
    @BindView(R.id.re22)
    RelativeLayout re22;
    @BindView(R.id.name)
    TextView name;
    @BindView(R.id.two)
    RelativeLayout two;
    @BindView(R.id.mylistview)
    MyListView mylistview;
    private PersenterMannaer persenterMannaer;

    IChildView iChildView = new IChildView() {
        @Override
        public void onSuccess(Databean s) {

        }

        @Override
        public void onError(String error) {

        }

        @Override
        public void ongetAddress_lvData(JavaBean_lv javaBean_lv) {

        }

        @Override
        public void ongetAddress_lvData2(JavaBean_lv2 javaBean_lv2) {

        }

        @Override
        public void ongetAddress_lvData3(JavaBean_lv3 javaBean_lv3) {

        }

        @Override
        public void ongetAddress_lvData4(JavaBean_msg javaBean_lv4) {

        }

        @Override
        public void ongetfriendSquareBean(FriendSquareBean friendSquareBean) {

        }

        @Override
        public void ongetfindfriend(FindFriend findFriend) {

        }

        @Override
        public void getjsonstring(FindTJBean s) {

        }

        @Override
        public void getfriendxxbean(FriendXxBean friendXxBean) {

            FriendXxBean.DataBean data = friendXxBean.getData();
            xrItemTitleSdf.setText(data.getTitle());
            name.setText(data.getUser().getName());
            Glide.with(Friend_xr_item_activity.this).load(data.getUser().getUsercover())
                    .apply(RequestOptions.circleCropTransform())
                    .into(xrItemHeadImageSdf);
            List<?> attach_imgs = data.getAttach_imgs();
            if (attach_imgs.size() == 0) {
                one.setVisibility(View.VISIBLE);
                three.setVisibility(View.GONE);
                two.setVisibility(View.GONE);
                Glide.with(Friend_xr_item_activity.this)
                        .load(data.getPoststd())
                        .into(leftimage2);

            } else if (attach_imgs.size() == 1) {
                two.setVisibility(View.VISIBLE);
                one.setVisibility(View.GONE);
                three.setVisibility(View.GONE);
                Glide.with(Friend_xr_item_activity.this)
                        .load(data.getPoststd())
                        .into(leftimage1);
                Glide.with(Friend_xr_item_activity.this)
                        .load(attach_imgs.get(0).toString())
                        .into(centerimage1);

            } else if (attach_imgs.size() == 2) {
                three.setVisibility(View.VISIBLE);
                two.setVisibility(View.GONE);
                one.setVisibility(View.GONE);
                Glide.with(Friend_xr_item_activity.this)
                        .load(data.getPoststd())
                        .into(leftimage);
                Glide.with(Friend_xr_item_activity.this)
                        .load(attach_imgs.get(0).toString())
                        .into(centerimage);
                Glide.with(Friend_xr_item_activity.this)
                        .load(attach_imgs.get(1).toString())
                        .into(rightimage);
            }
            time.setText("结伴时间:" + data.getStart_date() + "至" + data.getEnd_date());
            address.setText("出发地:" + data.getUser().getCity());

            xx.setText("详情:" + data.getDetail());
            numpeople.setText("我方人数:" + data.getPeople_num() + "人");
            tel.setText("联系方式:" + data.getContact());

            List<FriendXxBean.DataBean.ScenicsBean> scenics = data.getScenics();
            for (int i = 0; i < scenics.size(); i++) {
                FriendXxBean.DataBean.ScenicsBean scenicsBean = scenics.get(i);
                if (i == 0) {
                    Glide.with(Friend_xr_item_activity.this).load(scenicsBean.getScenestd())
                            .into(laddressimage);
                } else {
                    Glide.with(Friend_xr_item_activity.this).load(scenicsBean.getScenestd())
                            .into(laddressimage2);
                }


            }

        }

        @Override
        public void getIntrodution1(IntrodutioBean introdutioBean) {

        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_friend_xr_item_activity);
        ButterKnife.bind(this);

        Intent intent = getIntent();
        String uid = intent.getStringExtra("uid");

        persenterMannaer = new PersenterMannaer(this, "http://www.iqingyi.com/");

        persenterMannaer.onCreate();
        persenterMannaer.attchview(iChildView);
        persenterMannaer.getFriendxxBean(uid);


    }


    @OnClick({R.id.back, R.id.share, R.id.sxlz, R.id.xxly})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.back:
                finish();
                break;
            case R.id.share:
                break;
            case R.id.sxlz:
                break;
            case R.id.xxly:
                break;
        }
    }
}
